package com.example.administrator.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import com.example.administrator.myapplication.adapter.MyAdapter;
import com.example.administrator.myapplication.bean.Weather;
import com.example.administrator.myapplication.utli.GetJsonDataUtil;
import com.google.gson.Gson;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String TAG ="MainActivity" ;
    private ListView weatherListview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();

    }

    private void initView() {
        weatherListview = (ListView) findViewById(R.id.weather_listview);

    }

    private void initData() {
String jsonData =new GetJsonDataUtil().getJson(MainActivity.this,"data.json");
        Log.e(TAG, "initData: "+ jsonData );
        Gson gson =new Gson();
        //
        Weather weathers =gson.fromJson(jsonData,Weather.class);
        String todaytemperature =weathers.getResult().getToday().getTemperature();
        Toast.makeText(MainActivity.this,todaytemperature , Toast.LENGTH_SHORT).show();
    Weather.ResultBean.FutureBean futurebeans= weathers.getResult().getFuture();
        Log.e(TAG, "initData: "+futurebeans.getDay_20201215().toString()+"" );
        weatherListview.setAdapter(new MyAdapter(MainActivity.this, (List<Weather.ResultBean>) futurebeans));
    }

    private void initEvent() {

    }
}
